package business_logic.game_elements;


import java.util.Collection;
import java.util.EnumSet;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;


import business_logic.GameElement;
import business_logic.Tile;
import business_logic.view.GameViewIdentifier;

import model.collisions.CollisionCategory;
import model.elements.Wall;
import model.elements.attributes.Coordinate2D;
import model.exceptions.ModelExceptions;

public class BloqueAcero extends Wall implements GameElement
{
    private static final Collection<GameViewIdentifier> m_viewIdentifiers = 
                            EnumSet.of(GameViewIdentifier.SPRITE_BLOQUE_DE_ACERO);
    
    public BloqueAcero(Coordinate2D position) throws ModelExceptions
    {
    	super(position, CollisionCategory.C_T2_WALL, 1);
    }

    public Collection<GameViewIdentifier> getViewIdentifiers()
    {
        return m_viewIdentifiers;
    }

    @Override
    public void vivir()
    {
        try {
			this.update();
		} catch (ModelExceptions e) {
			e.printStackTrace();
		}
    }

    @Override
    public int getX()
    {
        return Tile.pixelToTile( m_currentPosition.getRealX() );
    }

    @Override
    public int getY()
    {
        return Tile.pixelToTile( m_currentPosition.getRealY() );
    }

    private static final long m_serialVersionUID = 1L;
    
    @Override
    public Element save()
    {
        Element elem = DocumentHelper.createElement( this.getClass().getName() );
        elem.addAttribute( "serialVersion", m_serialVersionUID+"" );
        elem.addAttribute( "x", Math.floor( this.getPosition().getRealX() ) +"" );
        elem.addAttribute( "y", Math.floor( this.getPosition().getRealY() ) +"" );
        
        return elem;
    }
    
    public BloqueAcero( Element elem ) throws ModelExceptions
    {
        super
        (
            new Coordinate2D
            (
                Double.parseDouble(elem.attributeValue("x")),
                Double.parseDouble(elem.attributeValue("y"))
            ),
            CollisionCategory.C_T2_WALL,
            1
        );
    }
}
